﻿<Window x:Class="WPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Controls="clr-namespace:XAMLPowerToys.Controls;assembly=XAMLPowerToys.Controls" 
        xmlns:v="clr-namespace:Chambills.Present.Validation;assembly=Present.Validation" xmlns:WPG="clr-namespace:WPG;assembly=WPG" xmlns:Emit="clr-namespace:System.Reflection.Emit;assembly=mscorlib" xmlns:System="clr-namespace:System;assembly=mscorlib" Title="Present Validation"
        Background="{StaticResource  {ComponentResourceKey TypeInTargetAssembly={x:Type WPG:PropertyGrid}, ResourceId=ContentBackgroundBrush}}"
        
        Height="350" Width="525">
    <Window.Resources>
        <v:ErrorContentConverter x:Key="safeAccessor" />
      <Style TargetType="TextBox" BasedOn="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type WPG:PropertyGrid}, ResourceId=TextBoxStyle}}" >
        <Setter Property="MinWidth" Value="150" />
        <Setter Property="Padding" Value="5" />
        <Setter Property="Validation.ErrorTemplate">
          <Setter.Value>
            <ControlTemplate>
              <DockPanel LastChildFill="True" >
                <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="14pt" Margin="0,0,0,0" FontWeight="Bold">*</TextBlock>
                <AdornedElementPlaceholder Name="controlWithError" />
              </DockPanel>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
        <Style.Triggers>
          <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="Background" Value="Pink" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="ToolTip" Value="{Binding  Path=(Validation.Errors), RelativeSource={RelativeSource Self}, Converter={StaticResource safeAccessor}}"  />
          </Trigger>
        </Style.Triggers>
      </Style>
      <Style TargetType="Controls:Form">
        <Style.Resources>
          <Style TargetType="Label">
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontWeight" Value="Medium"/>
          </Style>
        </Style.Resources>
        <Setter Property="Controls:FormItem.LabelWidth" Value="100" />
        <Setter Property="Controls:FormItem.LabelPosition" Value="Left" />
        <Setter Property="Controls:FormItem.LabelHorizontalContentAlignment" Value="Left" />
        <Setter Property="Controls:FormItem.LabelVerticalAlignment" Value="Center" />
        <Setter Property="Controls:FormItem.LabelPadding" Value="0,0,0,0" />
        <Setter Property="Controls:FormItem.ContentPadding" Value="3" />
      </Style>
    </Window.Resources>
    
  
  <!-- Form Content -->
    <StackPanel>
        <v:BrokenBindingNotifier PropertiesWithBrokenBindings="{Binding Validator.BrokenBindings}" />
        <Controls:Form Padding="20">
            <TextBox Controls:FormItem.LabelContent="_Firstname" Text="{v:ValidatedBinding FirstName}" />
            <TextBox Controls:FormItem.LabelContent="_Lastname" Text="{v:ValidatedBinding LastName}" />
            <TextBox Controls:FormItem.LabelContent="_Age" Text="{v:ValidatedBinding Age, TargetNullValue={x:Static System:String.Empty}}" />
        </Controls:Form>
        <Button Content="Save" Command="{Binding SaveCommand}" Width="50"/>
    </StackPanel>
</Window>
